using System;
using System.Collections.Generic;
using System.Text;

namespace RapidHDL
{
    public class TestCounter : RapidHardware
    {
        public override bool ConfigureSettings()
        {
            Settings.UseStart = false;
            Settings.BuildHardware = true;
            Settings.ForceBuildHardware = false;
            Settings.RunFromXilinx = true;
            Settings.ClockFrequency = 1;
            Settings.UseSDRAM = true;
            Settings.BuildRemote = false;
            return true;
        }

        public override bool GenerateStructure(TopLevelComponent TopLevelComponent)
        {
            UpCounter oUpCounter = new UpCounter(TopLevelComponent, "counter", TopLevelComponent.MainClock, 14, true, true, 0, 15 ,1);
            SystemInterface.AddSignalSource("enable", oUpCounter.EnableIn, 1);
            oUpCounter.ResetIn.Connection = TopLevelComponent.MainReset;

            TopLevelComponent.TestBusWrite.ConnectSubset(0, 0, oUpCounter.CountOut, 4, 4);
            TopLevelComponent.TestBusWrite.ConnectSubset(1, 12, Operators.CONST(TopLevelComponent, 0, 12), 0, 11);

            return true;
        }

        public override bool ConfigureSignalViews(TopLevelComponent TopLevelComponent)
        {
            SystemInterface.AddSignalView("count", "counter.COUNT_O");
            SystemInterface.FormatSignalView("count", SignalFormat.Unsigned);

            return true;
        }


        public override bool GenerateHardwareScripts()
        {
            HardwareScript oScript = HardwareScripts.NewScript("test");
            oScript.SignalView(5, "count");
            oScript.SignalCheck(8, "count", "8");
            oScript.Echo(9, "Echo Test");
            oScript.Pause(9);
            oScript.SignalCheck(10, "count", "10");
            oScript.SignalView(11, "count");

            return true;
        }

    }
}
